#include "copyright.h"
#include "process.h"
#include "addrspace.h"

//constructor
Process::Process(AddrSpace* mem) {

  pID = -1;
  space = mem;
  numThreads = 0;
}

//mutator
void Process::setID(int newID) {
  pID = newID;
}

//add a thread
int Process::addThread(Thread* t) {
  for (int i = 0; i<50;i++) {
    if (threadArray[i] == NULL) {//find first open space in the array
      threadArray[i] = t;//add new thread to the array
      numThreads ++;//increment number of threads
      return i;//return the index as the id
    }
  }
  return -1;//if there is no space return a -1
}

void Process::removeThread(Thread *t) {
  for (int i = 0;i<50;i++){
    if (t == threadArray[i]){
      threadArray[i] = NULL;      
      numThreads--;
      break;
    }
  }
}

void Process::deallocateSpace(AddrSpace* s){
  s->deallocateSpace();
}
